package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.parkcar.R;

import java.util.ArrayList;
import java.util.List;

import Modle.CouponBean;

/**
 * Created by Administrator on 2016/3/8.
 */
public class CouponAdapter extends BaseAdapter{
    private Context mContext;
    private List<CouponBean> mList = new ArrayList<>();
    public CouponAdapter(Context mContext){
        this.mContext = mContext;
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null){
            holder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.adapter_coupon,null);
            holder.acount_tv = (TextView) view.findViewById(R.id.acount_tv);
            holder.title = (TextView) view.findViewById(R.id.title);
            holder.end_time = (TextView) view.findViewById(R.id.end_time);
            view.setTag(holder);
        }else{
            holder = (ViewHolder) view.getTag();
        }
            CouponBean bean = mList.get(i);
        holder.end_time.setText("有效期："+bean.getEnd_at());
        holder.title.setText(bean.getTitle());
        holder.acount_tv.setText("￥"+bean.getAmount());
        return view;
    }
    class ViewHolder{
        TextView title,end_time,acount_tv;
    }
    public void setData(List<CouponBean> mList){
        this.mList = mList;
        notifyDataSetChanged();
    }
    public void addData(List<CouponBean> mList){
        this.mList.addAll(mList);
        notifyDataSetChanged();
}
}
